<?php echo get_header(); ?>
<form action="" method="get" id="user_index">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">
                    <i class="fa fa-list-ul"></i> 用户列表
                </div>

                <div class="card-block">
                    <div class="p-b-2" >
                        <a href="<?php echo url_for('/users/?action=add'); ?>" class="btn btn-success btn-sm"><i class="fa fa-plus"></i> 添加用户</a>
                        <div class="pull-right">
                            <?php echo get_default($paginator->getOffset(), 1); ?>-<?php echo $paginator->getLimit() + $paginator->getOffset(); ?>/<?php echo $total_rows; ?>
                            <div class="btn-group">
                                <a href="<?php echo $paginator->getPrevLink(); ?>" class="btn btn-default btn-sm" ><i class="fa fa-chevron-left"></i></a>
                                <a href="<?php echo $paginator->getNextLink(); ?>" class="btn btn-default btn-sm" ><i class="fa fa-chevron-right"></i></a>                                
                            </div>
                            <!-- /.btn-group -->
                        </div>
                        <!-- /.pull-right -->
                    </div>

                    <div class="table-responsive">
                        <table class="table table-hover table-outline mb-0 hidden-sm-down">
                            <thead class="thead-default">
                                <tr>
                                    <th>
                                        <input type="checkbox" id="chk-all">
                                    </th>
                                    <th>用户名</th>
                                    <th>邮箱</th>
                                    <th>昵称</th>
                                    <th>注册时间</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($users as $user) { ?>
                                    <tr>
                                        <td><input type="checkbox" class="chk-row"  name="users[id]" value="<?php echo $user->id; ?>"></td>
                                        <td><a href="<?php echo url_for('/users/', ['action' => 'edit', 'id' => $user->id]); ?>"><b><?php echo $user->username; ?></b></a></td>
                                        <td><a href="<?php echo url_for('/users/', ['action' => 'edit', 'id' => $user->id]); ?>"><b><?php echo $user->email; ?></b></a></td>
                                        <td><?php echo $user->display_name; ?></td>
                                        <td><?php echo date('Y-m-d H:i', $user->created_at); ?></td>
                                        <td><?php echo user_status_span($user->status); ?></td>
                                        <td>
                                            <a href="<?php echo url_for('/users/', ['action' => 'edit', 'id' => $user->id]); ?>" ><i class="fa fa-edit"></i> 编辑</a> 
                                            <a href="<?php echo url_for('/users/', ['action' => 'delete', 'id' => $user->id]); ?>" ><i class="fa fa-trash"></i> 删除</a>

                                        </td>
                                    </tr>
                                <?php } ?>

                            </tbody>
                        </table>
                        <?php echo $paginator->render(7, 'pagination pagination-sm m-top-none pull-right'); ?>
                    </div>

                </div>



            </div>

        </div>
    </div>


</form>
<?php Lg\View\JsBlock::begin(Lg\View\Asset::BODY_END); ?>
<script>
    $(function () {
        $('#chk-all').click(function () {
            if ($(this).is(':checked')) {
                $('.table').find('.chk-row').each(function () {
                    $(this).prop('checked', true);
                    $(this).parent().parent().parent().addClass('selected');
                });
            } else {
                $('.table').find('.chk-row').each(function () {
                    $(this).prop('checked', false);
                    $(this).parent().parent().parent().removeClass('selected');
                });
            }
        });
    });
</script>
<?php Lg\View\JsBlock::end(); ?>
<?php echo get_footer(); ?>
